package com.kfh.ybracelet.my;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.kfh.ybracelet.R;
import com.kfh.ybracelet.base.BaseActivity;
import com.kfh.ybracelet.utils.Constant;

/**
 * 性别修改
 * Created by Administrator on 2015/8/12.
 */
public class ChangeSexActivity extends BaseActivity {

    private static final int CHANGE_SEX_CODE = 10015;
    private ImageView cb_mal;
    private ImageView cb_femal;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_chang_sex);
//        mApplication.addActivity(this);
        init();
    }

    @Override
    public void widgetClick(View v) {
        switch (v.getId()) {
            case R.id.iv_left:
                finish();
                break;
            case R.id.tv_right://完成

//                SharedPreferences.Editor editor= sp.edit();
//
//                editor.putString(Constant.SEX,cb_mal.isSelected() ? "男" : "女");
//                editor.apply();

                Intent data = new Intent();

                data.putExtra("modifySex", cb_mal.isSelected() ? "男" : "女");

                setResult(CHANGE_SEX_CODE, data);

                finish();

                break;
            case R.id.rl_meal://男选中女不选中

                cb_mal.setSelected(true);
                cb_femal.setSelected(false);

                break;
            case R.id.rl_femal://女选中男不选中

                cb_mal.setSelected(false);
                cb_femal.setSelected(true);

                break;

        }

    }

    private void init() {
        ImageView tv_left = (ImageView) findViewById(R.id.iv_left);
        TextView tv_title = (TextView) findViewById(R.id.tv_title);
        TextView tv_right = (TextView) findViewById(R.id.tv_right);

        tv_title.setText(getResources().getString(R.string.change_sex));
        tv_right.setText(getResources().getString(R.string.done));

        RelativeLayout rl_meal = (RelativeLayout) findViewById(R.id.rl_meal);
        RelativeLayout rl_femal = (RelativeLayout) findViewById(R.id.rl_femal);


        tv_left.setOnClickListener(this);
        tv_right.setOnClickListener(this);

        rl_meal.setOnClickListener(this);
        rl_femal.setOnClickListener(this);

        cb_mal = (ImageView) findViewById(R.id.cb_mal);
        cb_femal = (ImageView) findViewById(R.id.cb_femal);

        cb_mal.setSelected(true);
        cb_femal.setSelected(false);
        //
        if (Constant.FREMAL.equals(sp.getString(Constant.SEX, ""))) {
            cb_mal.setSelected(false);
            cb_femal.setSelected(true);
        } else {
            cb_mal.setSelected(true);
            cb_femal.setSelected(false);
        }
    }
}
